package MainMethods;
import org.openqa.selenium.By;
import org.openqa.selenium.ElementNotVisibleException;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;

//String mouseOverScript = "if(document.createEvent){var evObj = document.createEvent('MouseEvents');evObj.initEvent('mouseover', true, false); arguments[0].dispatchEvent(evObj);} else if(document.createEventObject) { arguments[0].fireEvent('onmouseover');}";
//JavascriptExecutor js = (JavascriptExecutor) driver;
//WebElement someElem = driver.findElement(By.id("some Id")); //replace with your own WebElement call/code here
//js.executeScript(mouseOverScript, someElem);

public class HoverImage {
	// click button Play hovering image
	public void playHover(WebDriver driver) {
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {

			e.printStackTrace();
		}
		JavascriptExecutor jse = (JavascriptExecutor) driver;
		jse.executeScript("scroll(250, 0)");
		Actions hover = new Actions(driver);
		Actions hoverBtn = hover.moveToElement(driver.findElement(By
				.xpath("//*[@id=\"browse_element_wrapper\"]/div[8]/a")));
		hoverBtn.build().perform();
		driver.findElement(
				By.xpath("//*[@id=\"browse_element_wrapper\"]/div[8]/div/div/button"))
				.click();
	}

	// Click Add to queue button in plus menu
	public void addToQueue(WebDriver driver) {
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {

			e.printStackTrace();
		}
		Actions hover = new Actions(driver);
		Actions hoverBtn = hover.moveToElement(driver.findElement(By
		// *[@id="browse_element_wrapper"]/div[21]/a
				.xpath("//*[@id=\"browse_element_wrapper\"]/div[21]/a")));
		hoverBtn.build().perform();
		// click plus button
		driver.findElement(
		// *[@id="browse_element_wrapper"]/div[21]/div/div/div/button
				By.xpath("//*[@id=\"browse_element_wrapper\"]/div[21]/div/div/div/button"))
				.click();
		driver.findElement(
				By.xpath("//*[@id=\"browse_element_wrapper\"]/div[21]/div/div/div/ul/li[1]/a"))
				.click();

	}

	// click add to collection button in plus menu
	public void addToCollectionMus(WebDriver driver) {
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {

			e.printStackTrace();
		}
		JavascriptExecutor jse = (JavascriptExecutor) driver;
		jse.executeScript("scroll(250, 0)");
		Actions hover = new Actions(driver);
		Actions hoverBtn = hover.moveToElement(driver.findElement(By
				.xpath("//*[@id=\"browse_element_wrapper\"]/div[3]/a")));
		hoverBtn.build().perform();
		driver.findElement(
				By.xpath("//*[@id=\"browse_element_wrapper\"]/div[3]/div/div/div/button"))
				.click();
		driver.findElement(
				By.xpath("//*[@id=\"browse_element_wrapper\"]/div[3]/div/div/div/ul/li[2]/a"))
				.click();
	}

	public void playNowPlusMus(WebDriver driver) {
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {

			e.printStackTrace();
		}
		JavascriptExecutor jse = (JavascriptExecutor) driver;
		jse.executeScript("scroll(250, 0)");
		Actions hover = new Actions(driver);
		Actions hoverBtn = hover.moveToElement(driver.findElement(By
				.xpath("//*[@id=\"browse_element_wrapper\"]/div[1]/a")));
		hoverBtn.perform();
		// click plus button
		driver.findElement(
				By.xpath("//*[@id=\"browse_element_wrapper\"]/div[1]/div/div/div/button"))
				.click();
		driver.findElement(

				By.xpath("//*[@id=\"browse_element_wrapper\"]/div[1]/div/div/div/ul/li[3]/a"))
				.click();
	}

	public void moreInfoMus(WebDriver driver) {
		JavascriptExecutor jse = (JavascriptExecutor) driver;
		jse.executeScript("scroll(250, 0)");
		Actions hover = new Actions(driver);
		Actions hoverBtn = hover.moveToElement(driver.findElement(By
				.xpath("//*[@id=\"browse_element_wrapper\"]/div[2]/a")));
		hoverBtn.perform();
		// click plus button
		driver.findElement(
				By.xpath("//*[@id=\"browse_element_wrapper\"]/div[2]/div/div/div/button"))
				.click();
		driver.findElement(
		// *[@id="browse_element_wrapper"]/div[2]/div/div/div/ul/li[4]/a
				By.xpath("//*[@id=\"browse_element_wrapper\"]/div[2]/div/div/div/ul/li[4]/a"))
				.click();

	}

	public void addToCollection(WebDriver driver) {
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {

			e.printStackTrace();
		}
		JavascriptExecutor jse = (JavascriptExecutor) driver;
		jse.executeScript("scroll(250, 0)");
		Actions hover = new Actions(driver);
		Actions hoverBtn = hover.moveToElement(driver.findElement(By
				.xpath("//*[@id=\"browse_element_wrapper\"]/div[12]/a")));
		hoverBtn.perform();
		driver.findElement(
				By.xpath("//*[@id=\"browse_element_wrapper\"]/div[12]/div/div/div/button"))
				.click();
		driver.findElement(
				By.xpath("//*[@id=\"browse_element_wrapper\"]/div[12]/div/div/div/ul/li[1]/a"))
				.click();
	}

	// click play now in plus menu
	public void playNowPlus(WebDriver driver) {
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {

			e.printStackTrace();
		}
		JavascriptExecutor jse = (JavascriptExecutor) driver;
		jse.executeScript("scroll(250, 0)");
		Actions hover = new Actions(driver);
		Actions hoverBtn = hover.moveToElement(driver.findElement(By
				.xpath("//*[@id=\"browse_element_wrapper\"]/div[1]/a")));
		hoverBtn.perform();
		// click plus button
		driver.findElement(
				By.xpath("//*[@id=\"browse_element_wrapper\"]/div[1]/div/div/div/button"))
				.click();
		driver.findElement(
				By.xpath("//*[@id=\"browse_element_wrapper\"]/div[1]/div/div/div/ul/li[2]/a"))
				.click();
	}

	// click more info in plus menu
	public void moreInfo(WebDriver driver) {
		JavascriptExecutor jse = (JavascriptExecutor) driver;
		jse.executeScript("scroll(250, 0)");
		Actions hover = new Actions(driver);
		Actions hoverBtn = hover.moveToElement(driver.findElement(By
				.xpath("//*[@id=\"browse_element_wrapper\"]/div[2]/a")));
		hoverBtn.perform();
		// click plus button
		driver.findElement(
				By.xpath("//*[@id=\"browse_element_wrapper\"]/div[2]/div/div/div/button"))
				.click();
		driver.findElement(
				By.xpath("//*[@id=\"browse_element_wrapper\"]/div[2]/div/div/div/ul/li[3]/a"))
				.click();

	}

	public void moreLike(WebDriver driver) {
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		JavascriptExecutor jse = (JavascriptExecutor) driver;
		jse.executeScript("scroll(250, 0)");
		Actions hover = new Actions(driver);
		Actions hoverBtn = hover.moveToElement(driver.findElement(By
		// *[@id="related_container"]/div/div[3]/a
				.xpath("//*[@id=\"related_container\"]/div/div[3]/a")));
		hoverBtn.perform();
		driver.findElement(
				By.xpath("//*[@id=\"related_container\"]/div/div[3]/div/div/button"))
				.click();
	}

	// play from collection
	public void fromColl(WebDriver driver) throws ElementNotVisibleException {
		try {
			Actions hovcol = new Actions(driver);
			Actions colBtn = hovcol.moveToElement(driver.findElement(By
					.xpath("//*[@id=\"browse_wrapper\"]/div[2]/div[2]")));
			colBtn.perform();
			driver.findElement(
					By.xpath("//*[@id=\"browse_wrapper\"]/div[2]/div[2]/div[1]/div"))
					.click();
		} catch (NoSuchElementException e) {
			System.out.println("play from collection failed exception");
		}
	}

	// play now from because section
	public void becauseSect(WebDriver driver) {
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		JavascriptExecutor jse = (JavascriptExecutor) driver;
		jse.executeScript("scroll(250, 0)");
		Actions hovbec = new Actions(driver);
		Actions becBtn = hovbec.moveToElement(driver.findElement(By
				.xpath("//*[@id=\"browse_wrapper\"]/div[1]/div[9]/a")));
		becBtn.perform();
		driver.findElement(
				By.xpath("//*[@id=\"browse_wrapper\"]/div[1]/div[9]/div/div/button"))
				.click();
	}

	// filter in collection
	public void filterMusColl(WebDriver driver) {
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		driver.findElement(
				By.xpath("//*[@id=\"browse_wrapper\"]/div[2]/div[1]/span"))
				.click();
		driver.findElement(
				By.xpath("//*[@id=\"browse_wrapper\"]/div[2]/div[1]/ul/li[4]/a"))
				.click();

	}

	// verify does element on page
	public boolean doesElementExist(WebDriver driver, By elem) {

		if (driver.findElements(elem).size() > 0) {
			return true;

		} else {

			return false;

		}

	}

}
